import { useFetchYrRefs } from "./useFetchYr";
import { useFetchWinResRefs } from "./useFetchWinRes";

const useFetchData = defineStore("fetch-drawHist", () => {
  const resData = ref<Record<string, any>>({});
  const { yearList } = useFetchYrRefs();
  const { winResList } = useFetchWinResRefs();
  /*const FETCH_DELAY = 300;
  async function fetchData() {
    try {
      showLoading();
      resData.value = {};
      const res = await new Promise<Record<string, any>>(resolve => {
        const timer = setTimeout(() => {
          clearTimeout(timer);
          resolve({
            winRes: [
              {
                date: "16 ก.พ.",
                fullDate: "งวดวันที่ 16 กุมภาพันธ์ 2568",
                prize1: "847377",
                frontDigit: "50",
                front3Digits: ["268", "613"]
              },
              {
                date: "17 ก.พ.",
                fullDate: "งวดวันที่ 17 กุมภาพันธ์ 2568",
                prize1: "987654",
                frontDigit: "51",
                front3Digits: ["269", "614"]
              },
              {
                date: "18 ก.พ.",
                fullDate: "งวดวันที่ 18 กุมภาพันธ์ 2568",
                prize1: "123456",
                frontDigit: "52",
                front3Digits: ["270", "615"]
              }
            ],
            years: ["2568", "2569", "2570", "2571"]
          });
        }, FETCH_DELAY);
      });
      resData.value = res;
    } catch (error) {
      showError(error);
    } finally {
      closeLoading();
    }
  }*/
  function fetchData() {
    resData.value = {
      winRes: winResList,
      years: yearList
    };
  }
  onMounted(() => {
    fetchData();
  });

  return { resData };
});
export const useFetchDataRefs = () => storeToRefs(useFetchData());
export default useFetchData;
